home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / mony_121.zip / MONYDEMO.C < prev    next >
C/C++ Source or Header  |  1996-03-21  |  13KB  |  369 lines

  1. /* monydemo.c   */
  2.  
  3. // 24-Jan-96 - original (chh) */
  4. //  6-Feb-96 - changed cursor verify logic to not end demo if another Mony task running
  5. // 21-Mar-96 - changed logic so that more stuff is done even if only 1 page available
  6. // 21-Mar-96 - see EMX_MONY.ZIP for alternate source and header files
  7.  
  8.  
  9. /*  ------------------------------------------------- *
  10.  *  The demo requires that evaluation complete within *
  11.  *  25 minutes of each boot.  A license is needed to  *
  12.  *  use the Mony MDA BIOS emulator after the first 25 *
  13.  *  minutes.                                          *
  14.  *  ------------------------------------------------- */
  15.  
  16.  
  17. // Calls return 0xFF14 if Mony is busy.  This will only happen if another device driver
  18. // is using Mony's IDC entry and is calling a Mony routine at interrupt time.
  19. // Conversely, a Mony-using device driver calling Mony's IDC entry gets a 0xFE14 if
  20. // Mony is busy (i.e., ax=0FE14h, and the CF set as well).  Mony makes no system
  21. // calls except during init.  DevHlp is used for Beep'ing at WriteTTY and WriteString
  22. // when chr(7) is seen, and VerifyAccess for DosDevIOCtl processing.
  23.  
  24. // This demo program uses the simplified API found in monyapi.c.  All the register
  25. // set ups and IO Control calls are wrapped up in a pretty simple API.  Source is
  26. // included to change as you set fit.
  27.  
  28. // Most calls are supported with error checking, but some assume all is well (esp.
  29. // if a previous, indentical call, has been done.
  30.  
  31. #define INCL_BASE
  32. #define INCL_DOSDEVIOCTL
  33.  
  34. #include <os2.h>
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39.  
  40. #include "mony_api.h"
  41.  
  42. void AskForKey(void);   // proto misc routine
  43.  
  44. // Play ball!
  45.  
  46. APIRET main(void) {
  47.  
  48.    HFILE monyID=0;      // mony DD handle
  49.    ULONG action;        // open action
  50.    ULONG rc;            // result code
  51.  
  52.    PVOID bufferPtr=0;
  53.  
  54.    BIOSDATA VBD;        // Mony functionality info, 64 bytes' worth
  55.  
  56.    CHAR signOnStr[] = "Mony Demo - The second monitor is alive!\n";
  57.  
  58.    UCHAR i;             // working storage
  59.    UCHAR page;
  60.    UCHAR row;
  61.    UCHAR column;
  62.    UCHAR topLine;
  63.    UCHAR bottomLine;
  64.    UCHAR r0,c0;
  65.    UCHAR r1,c1;
  66.    UCHAR rows, columns;
  67.  
  68.  
  69.    setbuf(stdout,NULL);
  70.  
  71.    printf("\nMony Demo - Must be run within 25 minutes of booting with MONY.SYS. (21-Mar-96)\n\n");
  72.    printf("Most of the Mony functions are gone through at least once in the demo\n");
  73.    printf("following.  After each step, you're asked to press a key to move on to\n");
  74.    printf("the next.  Information is generally shown on the main display, with the\n");
  75.    printf("resulting action taking place over on the mony.  Right now, there should\n");
  76.    printf("be the Mony banner displaying. If not, make sure that the line\n\n");
  77.  
  78.    printf("     DEVICE=mony.sys [-p8] (8 video pages)\n\n");
  79.  
  80.    printf("is in config.sys, and that you just recently rebooted.  If still nothing,\n");
  81.    printf("call the BBS or visit the FTP site for a good version of the package.\n\n");
  82.  
  83.    printf("Mony runs on any dual-monitor system.  You can control it from a PM/WPS\n");
  84.    printf("program; a console program (like this one); or even from another physical\n");
  85.    printf("device driver via IDC (at task or interrupt time).  Tired of scrolling\n");
  86.    printf("PMprintf?  Want to work with a real screen, with up to 8 different pages?\n");
  87.    printf("Mony let's you.  You do need to pay for the software.  See the order form\n");
  88.    printf("for details.\n\n");
  89.  
  90.    AskForKey();
  91.  
  92.    printf("Opening Mony via DosOpen()...");
  93.  
  94.    rc = DosOpen("MONY$",&monyID,
  95.                 &action,0,
  96.                 FILE_NORMAL,FILE_OPEN,
  97.                 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,0);
  98.    if (rc) {
  99.       printf("Cannot open MONY$ device driver");
  100.       goto DieYoung;
  101.    }
  102.  
  103.    printf("okay.  Do you see anything different?\n");
  104.    printf("You shouldn't, not yet, but you will.\n");
  105.  
  106.    AskForKey();
  107.  
  108.    // Setting the video mode puts the Mony sub-system in a known state
  109.  
  110.    rc = MonySetVideoMode(monyID, 7);
  111.    if (rc) {
  112.       printf("Failed video mode set");
  113.       goto DieYoung;
  114.    }
  115.  
  116.    // Get and show the current state of affairs
  117.  
  118.    rc = MonyGetBiosData(monyID, &VBD);
  119.    if (rc) {
  120.       printf("Failed get data");
  121.       goto DieYoung;
  122.    }
  123.    printf("The GetBiosData() lets you check out vital stats.  For example:\n\n");
  124.    printf("Driver: v%i.%.3i  Mode: %i  Rows: %i  Cols: %i  Pages: %i\n\n",
  125.           VBD.monyVersion/1000, VBD.monyVersion % 1000,
  126.           VBD.videoMode, VBD.rows, VBD.columns, VBD.pages);
  127.    printf("There's more from where that came from, but you get the idea.\n");
  128.  
  129.    // Put something up over there
  130.  
  131.    printf("Check your Mony monitor!  It comes alive as soon as you...\n");
  132.    AskForKey();
  133.  
  134.    rc = MonyWriteString(monyID,
  135.                         signOnStr,      // what to write
  136.                         0,              // where to write (page)
  137.                         7,              // how to write (attr)
  138.                         0,0);           // spot to write (row,col)
  139.    if (rc) {
  140.       printf("Failed write string");
  141.       goto DieYoung;
  142.    }
  143.  
  144.  
  145.    printf("Well, what did you expect?  Maybe something a bit different?\n");
  146.    AskForKey();
  147.  
  148.    rc = MonyWriteString(monyID,
  149.                         signOnStr,      // what to write
  150.                         0,              // where to write (page)
  151.                         0x70,           // how to write (attr)
  152.                         1,0);           // spot to write (row,col)
  153.  
  154.    printf("Want more?  There are a few more tricks in that hat, but you find them.\n");
  155.    printf("Let's check out the cursor.  First, we'll show it, then move it around.\n");
  156.    AskForKey();
  157.  
  158.    rc = MonySetCursorSize(monyID,0,13); // shows fat cursor at 0,0 (from init above)
  159.    printf("You should be looking over there...\n");
  160.    DosSleep(2000);                      // wait a couple of seconds...(uh-oh, rc okay?)
  161.    rc = MonySetCursorPos(monyID,0,12,39); // page 0, row 12, column 39 (0=first)
  162.  
  163.    printf("\nHold on a sec while I verify that the cursor is fat and that the page 0\n");
  164.    printf("cursor is indeed at row 12, column 39 (0=first).  ");
  165.  
  166.    rc = MonyGetCursorStatus(monyID,0,&row,&column,&topLine,&bottomLine);
  167.    if ((row==12) & (column==39) & (topLine==0) & (bottomLine==13)) {
  168.       printf("Verified okay, as I expected.\nI'll turn that thing off in a couple.\n");
  169.    }
  170.    else {
  171.       if (rc==0) printf("\nNot verified.  Another Mony task has changed the cursor while I wasn't looking!\n");
  172.    }
  173.  
  174.    if (rc) {
  175.       printf("\nSomething is terribly wrong!  The world is ending!\n");
  176.       goto DieYoung;
  177.    }
  178.  
  179.    DosSleep(2000);
  180.    rc = MonySetCursorSize(monyID,0x20,0); // disable that thing
  181.  
  182.    // do some page flipping if more than 1 page available (/p option in DEVICE=)
  183.  
  184.    printf("\n");
  185.    if (VBD.pages < 2) {
  186.       printf("To see page flipping, add the /p# (#=1-8) option to the DEVICE= line.\n");
  187.       printf("For now, we'll just have to skip that demonstration.\n");
  188.    }
  189.    else {
  190.       printf("Let's check out the page memory.  The number of pages was shown up top here.\n");
  191.       AskForKey();
  192.  
  193.       for (page=0; page < VBD.pages; page++) {
  194.  
  195.          rc = MonySetCursorPos(monyID,page,0,0);        // position to start of page
  196.          rc = MonyWriteCharAttrAtCursor (monyID, page,  // do all pages, 1 at a time
  197.                                          (page + '0'),  // fill screen with page number
  198.                                          7,             // white on black
  199.                                          2000);         // 80x25
  200.          if (rc) break;
  201.       }
  202.       if (rc) {
  203.          printf("Page write failed big-time!\n");
  204.          goto DieYoung;
  205.       }
  206.  
  207.       printf("That was easy.  Each page is filled with its page number.  Let's\n");
  208.       printf("take a look at them, one after the other (1-second auto-mode).\n");
  209.       AskForKey();
  210.  
  211.       printf("Page: ");
  212.       for (page=0; page < VBD.pages; page++) {
  213.          printf("%i ",page);
  214.          rc = MonySetVideoPage(monyID,page);
  215.          DosSleep(1000);
  216.          if (rc) break;
  217.       }
  218.       if (rc) {
  219.          printf("\nSet Video Page failed enough to bug out!\n");
  220.          goto DieYoung;
  221.       }
  222.  
  223.       printf("\n\nToo slow, you say?  Let's do it without waiting.\n");
  224.  
  225.       AskForKey();
  226.  
  227.       printf("Page: ");
  228.       for (page=0; page < VBD.pages; page++) {
  229.          printf("%i ",page);
  230.          rc = MonySetVideoPage(monyID,page);      // since VBD.pages is 1-based!
  231.          if (rc) break;                           // and is not a valid page
  232.       }
  233.  
  234.       printf("\n\nYou probably missed it, but that was all %i pages zooming by.\n\n",VBD.pages);
  235.  
  236.       printf("How about some scrolling?  Scroll up, down, all around... up and\n");
  237.       printf("down, anyway.  That's followed up with copying the left half of the\n");
  238.       printf("screen over to the right half, via a ReadBlock and WriteBlock.  This\n");
  239.       printf("isn't your father's MDA BIOS!\n");
  240.    }
  241.  
  242.    AskForKey();
  243.  
  244.    // let's set everything back to square one by doing a mode set
  245.  
  246.    rc = MonySetVideoMode(monyID, 7);
  247.  
  248.    // how to demonstrate this... okay
  249.  
  250.    for (row=0; row < 25; row++) {
  251.       // you've seen these calls made already, above
  252.       rc = MonySetCursorPos(monyID,0,row,0);
  253.       rc = MonyWriteCharAttrAtCursor(monyID,0,(row + 'A'),7,39);  // only left half-1
  254.    }
  255.  
  256.    // so rows 0-24 from columns 0 to 38 are filled with letters...
  257.  
  258.    printf("I'm going to scroll up a block, without backfill, then scroll down\n");
  259.    printf("another area.  A 1/10th-second delay occurs between each 1-line scroll\n");
  260.    printf("up, and about 1/30th-second delay between each scroll down line.\n");
  261.    AskForKey();
  262.  
  263.    r0 = 2;
  264.    c0 = 3;
  265.    r1 = 20;
  266.    c1 = 16;
  267.    for (i=0; i <= (r1-r0); i++) {
  268.       rc = MonyScrollUp(monyID, 1,7, r0,c0, r1,c1);
  269.       DosSleep(100);
  270.    }
  271.  
  272.    DosSleep(500);   // digest it, then scroll another area, down this time
  273.  
  274.    r0 = 2;
  275.    c0 = 20;
  276.    r1 = 20;
  277.    c1 = 33;
  278.    for (i=0; i <= (r1-r0); i++) {
  279.       rc = MonyScrollDown(monyID, 1,7, r0,c0, r1,c1);
  280.       DosSleep(32);
  281.    }
  282.  
  283.    printf("Now I'm going to copy the left side of the screen to the right.\n");
  284.    AskForKey();
  285.  
  286.    r0 = 0;
  287.    c0 = 0;
  288.    rows = 25;
  289.    columns = 39;
  290.  
  291.    bufferPtr = malloc(rows*columns*2);
  292.    if (bufferPtr==NULL) {
  293.       printf("No go on the malloc'o\n");
  294.       rc = 8;
  295.       goto DieYoung;
  296.    }
  297.    rc = MonyReadBlock(monyID, bufferPtr, 0, r0,c0, rows,columns);
  298.    if (rc) {
  299.       printf("Whoa!  MonyReadBlock didn't want to play!  Goodbye sunshine.\n");
  300.       goto DieYoung;
  301.    }
  302.  
  303.    // copy it to row=0, but column=40 (i.e., copy from the left half to the right)
  304.  
  305.    c0 = 40;
  306.    rc = MonyWriteBlock(monyID, bufferPtr, 0, r0,c0, rows,columns);
  307.    if (rc) {
  308.       printf("Whoa!  MonyWriteBlock didn't want to play!  Hello moonshine.\n");
  309.       goto DieYoung;
  310.    }
  311.  
  312.    printf("That was fast!  I just copied (0,0)-(24,38) to (0,40)-(24,78).\n\n");
  313.  
  314.    printf("That's most of the stuff that Mony does, but not shown were:\n\n");
  315.  
  316.    printf("Reading page memory; Writing TTY style; sounding/setting the bell,\n");
  317.    printf("and a few others.  Also, not all modes were demonstrated for those\n");
  318.    printf("routines that were shown.  For example, WriteString has several modes\n");
  319.    printf("in how it prints.  The functionality, though, is documented in any BIOS\n");
  320.    printf("book or listing covering INT 10h, or in the included documentation.\n\n");
  321.  
  322.    printf("Mony is an emulator, true, but it also extends the standard BIOS support\n");
  323.    printf("to include the WriteString(), not found in any MDA BIOS, and the block\n");
  324.    printf("read and write routines, not found in any BIOS.  These, along with the\n");
  325.    printf("multiple video pages, and the speed of an assembly-written OS/2 device\n");
  326.    printf("driver, make for quite a package.\n\n");
  327.  
  328.    printf("Check it out.  If you like it, order a license and put it to work for you.\n");
  329.    printf("Device driver programmers can stop using DevHelp's Beep and finally get\n");
  330.    printf("real messages!  Application programs can use it for output without having\n");
  331.    printf("to find open desktop space, and using yet another buried window, and boring\n");
  332.    printf("TTY output, if even that.  By the way, did I mention... ");
  333.  
  334.    // That's the end of the show, folks!
  335.  
  336.    printf("That's all, folks!\n\n");
  337.  
  338.    // Say goodbye to Hollywood!
  339.  
  340. StayPretty:
  341.  
  342.    printf("Press a key, any key");
  343.    getchar();
  344.  
  345.    rc = MonySetVideoMode(monyID, 7);    // slippin' into darkness...(before close)
  346.  
  347.    if (monyID) DosClose(monyID);
  348.    if (bufferPtr) free(bufferPtr);
  349.    return rc;
  350.  
  351. DieYoung:
  352.    printf(", rc: %x\n",(rc & 255));
  353.    goto StayPretty;
  354.  
  355. }
  356.  
  357. // ------------------------------------------
  358. // do the mundane chore of asking for the key
  359.  
  360. void AskForKey(void) {
  361.  
  362.    printf("\n    Press a key (control-C to exit) ");
  363.    getchar();
  364.    printf("\n");
  365.    return;
  366. }
  367.  
  368.  
  369.